//
//  BK_Confirm_Order_FooterView.m
//  bestkeep
//
//  Created by TOPTEAM on 2017/2/21.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BK_Confirm_Order_FooterView.h"
#import "BK_OD_Color.h"
#import "BK_OD_Tool.h"
@implementation BK_Confirm_Order_FooterView
{
    UIView *_BGView;
    UILabel *_lab_PriceText;
    UILabel *_lab_PriceNumber;
    UIButton *_btn_submit;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initialize];
    }
    return self;
}

- (void)initialize
{
    _BGView = [[UIView alloc] init];
    _BGView.backgroundColor = kOrderBlack1;
    [self addSubview:_BGView];
    
    /*
     * 订单金额
     */
    _lab_PriceText = [[UILabel alloc] init];
    _lab_PriceText.textColor = [UIColor whiteColor];
    _lab_PriceText.backgroundColor = [UIColor clearColor];
    _lab_PriceText.textAlignment=NSTextAlignmentLeft;
    if (ScreenHeight<600) {
        _lab_PriceText.font = UIFontLarge;
    }else{
       _lab_PriceText.font = UIFontLargest;
    }
    
    _lab_PriceText.text = kOrderLocalizeString(@"BKOrderAmount");
    [self addSubview:_lab_PriceText];
    
    /*
     * 金额
     */
    _lab_PriceNumber = [[UILabel alloc] init];
    _lab_PriceNumber.textColor = [UIColor whiteColor];
    _lab_PriceNumber.textAlignment = NSTextAlignmentLeft;
    _lab_PriceNumber.backgroundColor = [UIColor clearColor];
    if (ScreenHeight<600) {
        _lab_PriceNumber.font = UIFontLarge;
    }else{
       _lab_PriceNumber.font = UIFontLargest;
    }
    
    [self addSubview:_lab_PriceNumber];
    
    /*
     * 提交订单
     */
    _btn_submit = [[UIButton alloc] init];
    [_btn_submit setTitle:kOrderLocalizeString(@"BKOrderSubmitOrders") forState:UIControlStateNormal];
    [_btn_submit setTitleColor:kOrderWhite forState:UIControlStateNormal];
    if (ScreenHeight<600) {
        _btn_submit.titleLabel.font = UIFontLarge;
    }else{
       _btn_submit.titleLabel.font = UIFontLargest;
    }
    
    [_btn_submit addTarget:self action:@selector(submitOrdersAction:) forControlEvents:UIControlEventTouchUpInside];
    UIImage *image = [Common imageWithFrame:CGRectMake(0, 0, 1, 1) color:kOrderBKGreen];
    [_btn_submit setBackgroundImage:image forState:UIControlStateNormal];
    UIImage *grayImage = [Common imageWithFrame:CGRectMake(0, 0, 0, 0) color:[UIColor grayColor]];
    [_btn_submit setBackgroundImage:grayImage forState:UIControlStateDisabled];
    [self setCanSubmit:NO];
    [self addSubview:_btn_submit];
    
    [self makeConstraints];
}

- (void)submitOrdersAction:(UIButton *)sender{
    if (self.delegate && [self.delegate conformsToProtocol:@protocol(BK_Confirm_Order_FooterView_Deleagte)]) {
        [self.delegate BK_Confirm_Order_FooterView_DidSelected:self];
    }
}

- (void)makeConstraints
{
    CGSize textSize;
    if (ScreenHeight<600) {
        textSize = [kOrderLocalizeString(@"BKOrderAmount") sizeWithAttributes:@{NSFontAttributeName : UIFontLarge}];
    }else{
       textSize = [kOrderLocalizeString(@"BKOrderAmount") sizeWithAttributes:@{NSFontAttributeName : UIFontLargest}];
    }
    
    
    
    [_lab_PriceText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(ApplicationBackGauge);
        make.width.mas_equalTo(textSize.width+15);
        make.centerY.equalTo(self);
    }];
    
    [_btn_submit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(self);
        make.width.offset(130);
    }];
    
    [_BGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.mas_equalTo(self);
        make.right.mas_equalTo(_btn_submit.mas_left);
    }];
    
    [_lab_PriceNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_lab_PriceText.mas_right).offset(0);
        make.right.equalTo(_btn_submit.mas_left).offset(-10);
        make.centerY.equalTo(self);
    }];
}

- (void)setOrderPrice:(NSString *)orderPrice{
    _orderPrice = orderPrice;
    _lab_PriceNumber.text = [NSString stringWithFormat:@"￥%@",orderPrice];
}

- (void)setCanSubmit:(BOOL)canSubmit
{
    if (canSubmit) {
        _btn_submit.enabled = YES;
    }
    else{
        _btn_submit.enabled = NO;
    }
}

@end
